-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Abstract away the parameters into a parameters class #16
base: master
Are you sure you want to change the base?
Conversation
add github's default .gitignore file for python projects (with .python-version)
Potential problems I came up with a while ago:
|
You could simply use the same parameter names such as
You can compose a parameters class made up of multiple sub-classes, in the same way that is now already being done with the option 1, create the default parameters and override options:
option 2: have it parse a dictionary
|
Oh, another issue I came up with is that external models (not from Discretization.py) also use e.g. Continuation.py and the eigenvalue solver interface. They have a huge range of parameters. See for instance the list here: https://github.com/nlesc-smcm/pop-iemic-examples/blob/main/iemic.py#L79 We want to keep that use case working as well. |
I'm not sure which of the arguments above still apply to the current code, nearly 1.5 years after your discussion. My impression is that with !42 !43, the main obstacle to parameters (data)classes has been removed. Any discretization & interface implementing parameter dictionaries or dataclasses must just implememt If the code must be compatible with Python 3.6 (i.e., no dataclasses), I think normal classes are still preferable to dictionaries. What are your thoughts on this now? |
I don't have the design clear here nor the time to dive into it, but in general everything Mark said is right. Classes are self-documenting in that at least you know which parameters there are, and with type annotations and a type checker you can find many issues much more easily. And as Mark also pointed out, Python has plenty introspection to be able to convert between things as needed. (The iemic example linked above actually shows how OMUSE uses a class-based interface, which has As for Python 3.6, I'm pretty conservative with what I support, but the Python community tends to limit support for new releases to Python versions still in official support. Since many packages on PyPI have broken metadata, installing anything on a no-longer-supported version gets difficult pretty quickly, which incentivises people to upgrade. So even though e.g. Ubuntu 18.04 has Python 3.6 and has (paid) support until 2028, anyone still running that OS has already installed a newer Python on it by now. The upshot is that as of last week, you can take 3.9 as a minimum for new releases without upsetting anyone. |
I see a lot of the issues have already been solved by explicitly listing the parameters in the constructors, instead of accepting an arbitrary dictionary. If you wish to have an equivalent of dataclasses, that works on Python3.6, you could consider attrs (it's also better than regular dataclasses). Feel free to close this PR! |
Pro's of a parameter class:
Dependencies
For now I used the builtin
dataclass
object. But we could switch to Pydantic / attrs that automatically bring some validation and some other features.Discussion
I haven't looked at the interaction with the Teuchos parameterlist. I should check how this interacts.
@Sbte are there other libraries that depend on the old spelling of the parameters? Or is it just Teuchos?
We could also add some conditional checks. For some problem spaces, some parameters do not make sence. It would be nice that those parameters are then also not possible to be set.
TODO